#!/usr/bin/env python
# encoding: utf-8
'''
@author: guihehans
@file: sql_mapping.py
@time: 2020/4/7 14:55
@function:

'''
SQL_MAPPING = {
    'redmine': "SELECT value FROM custom_values WHERE customized_id =%s AND custom_field_id = '18'",
    'zeus': "select * from release_record where task_id = '#%s' and release_count is not NULL",
    'get_task_status_from_redmine': "select issues.status_id,issue_statuses.name from issues ,issue_statuses where issues.status_id = issue_statuses.id and issues.id = %s",
    'cmdb_get_release_versions': "select sys_id, qa_version,release_version,release_count,release_env from release_record where task_id='#%s';",
    'get_release_versions_to_deploy_on_pre': "select sys_id, qa_version,release_version,release_count,release_env, deploy_count, create_time from release_record where task_id='#%s' and release_env='pre';",
    'get_release_versions_to_deploy_on_prod': "select sys_id, qa_version,release_version,release_count,release_env, deploy_count, create_time from release_record where task_id='#%s'and release_env='prod';"
}

COLUMN_MAPPING = {
    'redmine': 'value',
    'zeus': 'qa_version'
}

# zeus info query sql
# select
# t.id,t.sys_id,i.env_id,unit_id,deploy_path,config_path,log_path,t.status,
# t.remark,t.update_date,t.create_person,t.update_person,
# i.server_ip_address as sysName,e.env_name as envName,
# CONCAT(ru.sys_id,'_',ru.sys_name) as unitName,ru.sys_cname as unitCName,
# date_format(t.create_date,'%Y-%m-%d %T') as createTime,
# t.server_port
# from t_cmdb_deploy_info t
# inner JOIN t_cmdb_server_info i on t.sys_id = i.id
# left join t_conf_release_unit ru on t.unit_id = ru.id
# left join t_environment e on i.env_id = e.id
# where ru.unit_status != '2' AND unit_id =(select id  from  t_conf_release_unit where sys_id='ld139')
# AND env_id=23